# coding=utf-8
from __init__ import *


class MovableUi(Base):
    """
    可控的移动性Ui
    以当前位置为原点,位置随时间变化
    """

    def __init__(self, base_ui_control, moving_route_x=lambda t: 0, moving_route_y=lambda t: 0):
        # type:(BaseUIControl,Any,Any)->None
        """
        @param base_ui_control: ui控件
        @param moving_route_x: x轴的运动路径
        @param moving_route_y: y轴的运动路径
        """
        self.baseUiControl = base_ui_control
        self.movingRouteX = moving_route_x
        self.movingRouteY = moving_route_y
        self.initialPos = base_ui_control.GetPosition()
        Base.__init__(self)

    def ResetRouteX(self, routeX=lambda t: 0):
        """
        设置为新的X轴运动函数
        :param routeX: 函数, 传参运动时间
        :return:
        """
        self.Reset()
        self.movingRouteX = routeX

    def ResetRouteY(self, routeY=lambda t: 0):
        """
        设置为新的Y轴运动函数
        :param routeY: 函数, 传参运动时间
        :return:
        """
        self.Reset()
        self.movingRouteY = routeY

    def Refresh(self):
        if self.state != ControlState.Run:
            return
        runTime = self.GetWorkTime()
        self.baseUiControl.SetPosition((
            self.movingRouteX(runTime) + self.initialPos[0], self.movingRouteY(runTime) + self.initialPos[1]
        ))
        return runTime
